<?

function _template_filter_entry ($filter, $indexes, $i=0) {

	$value = $_REQUEST[$filter."_value"][$i];
	if ($i > 0) {

		$filter_delete_open = "<div class=\"vmc_icon_filter_delete\" onclick=\"javscript: delete_filter (this);\">";
		$filter_delete_close = "</div>";
	} else {

		$filter_delete_open = null;
		$filter_delete_close = null;
	}

	print <<<HTML
<tr id="{$filter}" count="0">
	<td align="right">{$filter_delete_open}<div id="search_label" class="vmc_icon_filter_label">Search For: </div>{$filter_delete_close}</td>
	<td width="150px"><input name="{$filter}_value[]" class="vmc_fieldset_value" value="{$value}" type="input"></td>
	<td>Filter List By: </td>
	<td width="150px">
	<select class="vmc_fieldset_value" name="{$filter}[]">

HTML;

	foreach ($indexes as $key => $val) {

		if (isset ($val["no_filter"])) continue;

		$value = isset ($val["alias"]) ? $val["alias"] : $key;
		$select = ($_REQUEST[$filter][$i] == $key) ? " selected" : null;

		print <<<HTML
		<option{$select} value="{$key}">{$val["label"]}</option>

HTML;
	}

	print <<<HTML
	</select>
	</td>
</tr>

HTML;
}

function _template_list_filter ($container) {

	$indexes = $container->get_variable ("indexes");
	$list_check_box = $container->get_variable ("list_check_box");
	//print_r ($indexes);
	$filter = "filter_{$container->get_variable ("list_id")}";
	$index_count = count ($indexes) + ($list_check_box ? 1 : 0);

	$_SERVER["QUERY_STRING"] = preg_replace ("/{$filter}_reset=true/", "", $_SERVER["QUERY_STRING"]);
	$action = $_SERVER["PHP_SELF"] . isset ($_SERVER["QUERY_STRING"]) ? "?{$_SERVER["QUERY_STRING"]}" : null;

	print <<<HTML
<tr>
	<td colspan="{$index_count}" align="right">

<!-- begin filter form -->
<form method="POST" name="form_{$filter}" action="{$action}">

<!-- begin filter container -->
<div class="vmc_list_filter_container" id="vmc_list_filter_container">
	<div class="vmc_list_filter_control" onclick="javascript: toggle_filter ('{$filter}_control');">View Filter</div>
	<div class="vmc_list_filter vmc_list_filter_hidden" id="{$filter}_control">

<!-- script language="JavaScript">$('#{$filter}_control').hide('fast');</script -->

<!-- begin filter table -->
<table class="vmc_list_filter" cellpadding="2" cellspacing="3">

HTML;


	if (count ($_REQUEST[$filter])) {

		foreach ($_REQUEST[$filter] as $key => $val) {

			_template_filter_entry ($filter, $indexes, $key);
		}
	} else {

		_template_filter_entry ($filter, $indexes);
	}

	$reset = $_SERVER["PHP_SELF"] . "?{$filter}_reset=true&{$_SERVER["QUERY_STRING"]}";

	print <<<HTML
<tr id="{$filter}_ctl">
	<td colspan="4" align="right"><a class="vmc_filter_link" href="{$reset}">&raquo;&nbsp;Reset Filter</a>&nbsp;&nbsp;<a class="vmc_filter_link" href="javascript: clone_filter ('{$filter}');">&raquo;&nbsp;Add Filter Item</a>&nbsp;&nbsp;<a class="vmc_filter_link" href="javascript: document.form_{$filter}.submit();">&raquo;Filter List</a></td>
</tr>
<!-- end filter table -->
</table>

<!-- end filter container -->
</div>

<!-- end filter form -->
</form>

	</td>
</tr>

HTML;
}

function _template_list_begin ($container) {

	print <<<HTML
<div class="vmc_list_table" id="{$container->get_variable ("list_id")}">
<table class="vmc_list_a" border="0" cellpadding="2" cellspacing="0" width="100%">

HTML;

	if ($list_title = $container->get_variable ("list_title")) {
		
	print <<<HTML
<tr><td class="vmc_list_title" colspan="{$container->get_variable ("column_count")}">{$list_title}</td></tr>

HTML;
	}
}

function _template_list_options_begin ($container) {

	print <<<HTML

<tr>
	<td class="vmc_list_options" align="left" colspan="{$container->get_parent ()->get_variable ("column_count")}">

<br>
<table class="vmc_form_a" border="0" cellpadding="2" cellspacing="0" width="100%">

HTML;
}

function _template_list_option ($container) {

	$wrapper = ($wrapper = $container->get_option ("wrapper")) ? $wrapper : "vmc_button_addnew";
	print <<<HTML
	<form action="{$container->get_option ("link")}" method="POST"><td width="10"><input class="vmc_list_option {$wrapper}" type="submit" value="{$container->get_option ("label")}"></td></form>

HTML;
}

function _template_list_js_option ($container) {

	print <<<HTML
	<button onclick="">

HTML;
}

function _template_list_options_end ($container) {

	$scroll_options = array ();
	$object_id = $container->get_variable ("object_id");

	if ($container->get_variable ($object_id . "_page") > 1) {

		$scroll_a =<<<HTML
<a href="?{$object_id}_page=1&{$object_id}_action=first{$container->get_variable ("link_options")}"><img border="0" src="/admin/img/arrow1b.gif" alt="First Page"></a>
HTML;
	} else {

		 $scroll_a = <<<HTML
<img border="0" src="/admin/img/arrow1a.gif">
HTML;
	}

	if ($container->get_variable ($object_id . "_prev")) {

		$scroll_b = <<<HTML
<a href="?{$object_id}_action=prev&{$object_id}_page={$container->get_variable ($object_id . "_page")}{$container->get_variable ("link_options")}"><img border="0" src="/admin/img/arrow2b.gif" alt="Previous Page"></a>
HTML;
	} else {

		$scroll_b = <<<HTML
<img border="0" src="/admin/img/arrow2a.gif"></a>
HTML;
	}

	if ($container->get_variable ($object_id . "_next")) {

		$scroll_c = <<<HTML
<a href="?{$object_id}_action=next&{$object_id}_page={$container->get_variable ($object_id . "_page")}{$container->get_variable ("link_options")}"><img border="0" src="/admin/img/arrow3b.gif" alt="Next Page"></a>
HTML;
	} else {

		$scroll_c = <<<HTML
<img border="0" src="/admin/img/arrow3a.gif">
HTML;
	}

	if ($container->get_variable ($object_id . "_page") <
			$container->get_variable ($object_id . "_pages")) {

		$scroll_d = <<<HTML
<a href="?{$object_id}_page={$container->get_variable ($object_id . "_pages")}&{$object_id}_action=last{$container->get_variable ("link_options")}"><img border="0" src="/admin/img/arrow4b.gif" alt="Last Page"></a>
HTML;
	} else {

		$scroll_d = <<<HTML
<img border="0" src="/admin/img/arrow4a.gif">
HTML;
	}

	print <<<HTML
	<td class="" width="100%" align="right">&nbsp;</td>
	<td style="font-size:8px;" align="right" valign="center">{$scroll_a}&nbsp;&nbsp;{$scroll_b}&nbsp;&nbsp;{$scroll_c}&nbsp;&nbsp;{$scroll_d}&nbsp;&nbsp;</td>
</tr>
</table>

	</td>
</tr>

HTML;
}

function _template_list_end ($container) {

	print <<<HTML
</table>
</div>
<br>


HTML;
}

function _template_list_indexes_begin ($container) {

	print <<<HTML
<tr class="vmc_list_indexes">

HTML;
}

function _template_list_indexes_end ($container) {

	print <<<HTML
</tr>

HTML;
}

function _template_list_index ($container) {

	$options = $container->get_variable ("options");
	if (!$options["no_index"])  {

		$img=<<<HTML
<img hspace="4" border="0" src="/admin/img/{$container->get_variable ("image")}">
HTML;
		$img = $container->get_variable ("image");
	}

	print <<<HTML
	<td class="{$container->get_variable ("class_a")}" valign="center" onmouseover="javascript: this.className='{$container->get_variable ("class_b")}';" onmouseout="javascript: this.className='{$container->get_variable ("class_a")}';"><a class="vmc_indexing {$img}" href="?{$container->get_variable ("list_id")}_order={$container->get_variable ("order")}{$container->get_variable ("link_options")}">{$container->get_variable ("label")}</a></td>

HTML;
}

function _template_list_row_begin ($container) {

#<tr onmouseover="javascript: this.className = 'vmc_cell_b';" onmouseout="javascript: this.className = 'vmc_cell_a';">
	$class = $container->get_option ("class");

	print <<<HTML
<tr class="{$class}" onmouseover="javascript: this.className='vmc_list_control_row_b';" onmouseout="javascript: this.className='{$class}';">

HTML;
}

function _template_list_row_end ($container) {

	print <<<HTML
</tr>

HTML;
}

function _template_list_row_column ($container) {

	$column = $container->get_variable ("column");
	$align = isset ($column["align"]) ? " align=\"{$column["align"]}\"" : null;
	$valign = isset ($column["valign"]) ? " valign=\"{$column["valign"]}\"" : null;

	if (isset ($column["callback"]) && function_exists ($column["callback"])) {

		if ($value = $column["callback"] ($container, $column))

			$container->set_variable ("value", $value);
		else return;
	} elseif (isset ($column["substring"])) {

		$value = $container->get_variable ("value");
		$value = strlen ($value) > 16 ? substr ($value, 0, 13) . "..." : $value;
	} else $value = $container->get_variable ("value");

	if (isset ($column["wrapper"])) {

		$value = _app_column_wrapper ($container, $column);
	}

	if ($container->get_variable ("object_ctl_off")) {

		$href = null;
	} elseif ($href = $container->get_variable ("object_ctl")) $href = " href=\"{$href}\"";

	print <<<HTML
	<td{$align}{$valign} class="vmc_list_control_column_a"><a class="vmc_list_control_column_a"{$href}>{$value}</a></td>

HTML;
}

function _template_list_substring ($container, $column) {

	$value = $container->get_variable ("value");
	return (strlen ($value) < $column["length"] ? $value : substr ($value, 0, $column["length"] - 3) . "...");
}

function _template_list_image_value ($container, $column) {

	if (!file_exists ("{$_SERVER["DOCUMENT_ROOT"]}/{$column["path"]}/" .
			"{$container->get_variable("value")}.jpg"))
		return "&nbsp;";

	if ($container->get_variable ("object_ctl_off")) {

		$href = null;
	} else $href = " href=\"{$container->get_variable ("object_ctl")}\"";

	print <<<HTML
	<td align="center" class="vmc_list_control_column_a"><a class="vmc_list_control_column_a"{$href}><img  border="0" src="/scale.php?path={$column["path"]}/{$container->get_variable("value")}.jpg&scale={$column["scale"]}"></a></td>

HTML;

}

function _app_column_wrapper (&$container,$column) {

	$row = &$container->get_variable ("row");

	return <<<HTML
<div class="{$column["wrapper"]}">{$container->get_Variable ("value")}</div>
HTML;
}

function _app_get_cookie ($name) {

	$_cookies = split ("; ", $_SERVER["HTTP_COOKIE"]);

	foreach ($_cookies as $value) {

		$c = split ("=", $value);
		if ($name == $c[0]) return $c[1];
	}
}

function _template_list_row_checkbox ($container) {

	$list_id = $container->get_variable ("list_id");
	$row = $container->get_variable ("row");

	if (preg_grep ("/{$row->id}/", split (":", _app_get_cookie ($list_id)))) 
		$checked = " checked";

	print <<<HTML
	<td align="center" class="vmc_list_control_column_a"><input id="{$row->id}" list_object="{$list_id}"{$checked} class="vmc_fildset_field" onclick="javascript:list_checkbox_toggle (this);" type="checkbox" name="{$list_id}_checkbox[]" value="{$row->id}"></td>
HTML;
	return false;
}

?>
